package com.netease.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;

import com.netease.domain.ShoppingCart;
import com.netease.domain.User;
import com.netease.domain.User_Commodity;
import com.netease.service.ShoppingcartService;
import com.netease.service.UserCommodityService;

/**
 * Servlet implementation class Ajax
 */
@WebServlet("/changeNum")
public class ChangeShoppingCartCommodityNumServlet extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = -5161371054837131131L;
	/**
	 * 
	 */


	@Autowired
	private ShoppingcartService shoppingcartService;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public ChangeShoppingCartCommodityNumServlet() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		this.doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");
		String id = request.getParameter("id");
		int amount = Integer.parseInt(request.getParameter("amount"));
		ShoppingCart sc = shoppingcartService.findOne(id);
		sc.setAmount(amount);
		shoppingcartService.update(sc);

	}

}
